#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

// 判断甲是否赢
bool isWin(char a, char b) {
    return (a == 'C' && b == 'J') ||
           (a == 'J' && b == 'B') ||
           (a == 'B' && b == 'C');
}

// 获取胜率最高的手势
char getBestMove(const map<char, int>& winCount) {
    vector<pair<int, char>> candidates;
    for (auto& p : winCount) {
        candidates.push_back({-p.second, p.first}); // 使用负号实现降序排序
    }
    sort(candidates.begin(), candidates.end());
    return candidates[0].second;
}

int main() {
    int n;
    cin >> n;

    int winA = 0, drawA = 0, loseA = 0;
    int winB = 0, drawB = 0, loseB = 0;

    map<char, int> winCountA = {{'C', 0}, {'J', 0}, {'B', 0}};
    map<char, int> winCountB = {{'C', 0}, {'J', 0}, {'B', 0}};

    for (int i = 0; i < n; ++i) {
        char a, b;
        cin >> a >> b;

        if (a == b) {
            drawA++;
            drawB++;
        } else if (isWin(a, b)) {
            winA++;
            loseB++;
            winCountA[a]++;
        } else {
            winB++;
            loseA++;
            winCountB[b]++;
        }
    }

    // 输出甲的战绩
    cout << winA << " " << drawA << " " << loseA << endl;
    // 输出乙的战绩
    cout << winB << " " << drawB << " " << loseB << endl;
    // 输出胜率最高的手势
    cout << getBestMove(winCountA) << " " << getBestMove(winCountB) << endl;

    return 0;
}